<?php
$posts = $args['posts'] ?? [];
if (empty($posts)) {
    $posts = get_random_posts($args['pagesize'] ?? 8);
}
?>
<div class='cti2'>
    <section class="i2">
        <?php
        foreach ($posts as $post) {
        ?>
            <a class="grid" href="<?= $post['link'] ?>" title="<?= $post['title'] ?>">
                <section class="grid">
                    <h3 class="nowrap2"><?= $post['title'] ?></h3>
                    <span><?= $post['date'] ?></span>
                </section>
                <img src="<?= $post['thumbnail'] ?>" alt="<?= $post['title'] ?>">
            </a>
        <?php
        }
        ?>
    </section>
</div>
<style>
    div.cti2 {
        container-type: inline-size;
        container-name: i2;
    }

    section.i2 {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: var(--gap);
    }

    section.i2>a {
        grid-template-columns: 5fr 3fr;
        position: relative;
        border: 1px solid var(--color-border);
        border-radius: var(--border-radius);
        transition: var(--transition);
        background-color: var(--color-primary);
    }

    section.i2>a>img {
        width: 100%;
        height: 10rem;
    }

    section.i2>a>section {
        padding: var(--gap);
    }

    section.i2>a>img:hover,
    section.i2>a>section:hover {
        cursor: pointer;
    }

    @container i2 (max-width: 1200px) {
        section.i2>a>img {
            height: 8rem;
        }
    }

    @container i2 (max-width: 1024px) {
        section.i2>a {
            grid-template-columns: auto;
        }

        section.i2>a>img {
            height: 12rem;
        }

        section.i2>a:nth-child(3)>img,
        section.i2>a:nth-child(4)>img {
            height: 12rem;
        }


    }

    @container i2 (max-width: 768px) {
        section.i2 {
            grid-template-columns: 1fr 1fr;
        }

        section.i2>a:nth-child(3) {
            grid-column: auto;
        }

        section.i2>a:nth-child(4) {
            grid-column: auto;
        }

        section.i2>a>img {
            height: 16rem;
        }
    }

    @container i2 (max-width: 576px) {
        section.i2 {
            grid-template-columns: 1fr;
        }
    }
</style>